home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
I-Z
/
Progress Tube Unit.cpt
/
Progress Tube Unit Folder
/
Progress Tube Instructions.c
next >
Wrap
Text File
|
1992-12-31
|
4KB
|
106 lines
/*
<chriskline@aol.com> Dec 31, 1992...
This little unit I hope will help those who want to use progress tubes (the
familiar "thermometer bar" tubes you see while you're waiting for your
sub-quadra class mac to do something useful). There are only four functions,
which I hope will simplify the use of my routines.
The first thing you need to do is #include "ProgressTube.h" in your source file.
Then declare a variable of type TubeType in your code. To create a new tube, just
say:
OSErr didItWork; // was there enough memory for the new tube?
TubeType myTube; // the tube data structure
Str255 myTubeWindowTitle; // the title of the new tube window
didItWork = NewTube( &myTube, myTubeWindowTitle );
if ( didItWork <> noErr )
{
fill it, do other processing etc in here...
}
Note: you can pass an actual string of characters
(i.e.; "\pThis is my tube window title...") in place of the myTubeWindowTitle
Str255, as long as it's a Pascal-style string (i.e.; prefixed with a length byte,
or a "\p" in Think C). You can also pass NULL as the title string, in which case
NewTube() will use the constant kDefaultTubeTitle defined in the header file. You
may make the default title whatever you want, but it is initially set to an empty
string (no title).
Note: the tube created will be in a window of the Movable-modal dialog appearance.
This is so that even though it's not really modal, it looks cool. You can change
the window definition procedure by changing the constant kDefaultTubeType defined
in the header file. (it is initially set to 5, the movableModal definition)
Note: if you want to have the progress tube centered on the main screen, call the
function:
CenterTube ( myTube )
otherwise it will appear in the position defined by the variable defaultRect,
which I have initially set to be correct for centering on a 9" screen.
Now for the good stuff. To fill the tube, just call the function:
float thePercentageToFill; // percentage to fill, as a decimal
FillTube( myTube, myMessageString, &thePercentageToFill);
myMessageString is the message to be displayed just above the fill tube, and will
be displayed in the font and size defined in the header file under the constants
kDefaultFontNum and kDefaultFontSize. You can also pass NULL as the message string,
in which case FillTube() will use the constant kDefaultTubeMessage defined in the
header file. You may make the default message whatever you want, but it is
initially set to "\pPlease wait..."
thePercentageToFill is the percentage to fill the tube, as a decimal. For example,
if your process was half finished, you would say:
float thePercentageToFill
thePercentageToFill = .50;
FillTube( myTube, "\pHalf done! Be patient...", &thePercentageToFill);
for example, if you were loading in a file, you could set thePercentageToFill equal
to the total number of bytes already read divided by the total number of bytes in
the file, and call FillTube() every time you read in more of the file.
Note: it is very important to send in a VARIABLE of type float, because the
function expects a pointer to a floating point number, and if you send in
something like :
FillTube( myTube, "\pHalf done! Be patient...", 50/100 );
the function will puke and crash.
Finally, to dispose of a tube, just send it into the function
DisposeTube ( myTube );
and that's it! It will deallocate the window memory for you.
I hope these functions are useful. I found them to be so, so please let me know
if you use them, just so I can say, "wow! I've done something useful with my life!"
Oh, BTW, if you are running an event loop in between filling the tube, and you want
to know if the window that an event occurred in was a tube window, you may know
that the NewTube() function sets the refCon field of the tube's windowptr to be
(long) "TUBE". So you can check if it's a tube by saying
if ( PointerToTheWindowAnEventOccuredIn->refCon == (long)"TUBE" )
{
do whatever you want
}
Good luck, and drop me some email at <chriskline@aol.com>
*/